import React from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { RootState } from './store/store';
import { makeStyles } from '@fluentui/react-components';

// 导入页面组件
import LoginPage from './pages/LoginPage';
import DashboardPage from './pages/DashboardPage';
import OpportunityListPage from './pages/OpportunityListPage';
import OpportunityDetailPage from './pages/OpportunityDetailPage';
import BusinessPlanPage from './pages/BusinessPlanPage';
import ProgressTrackingPage from './pages/ProgressTrackingPage';
import RiskManagementPage from './pages/RiskManagementPage';
import AnalyticsPage from './pages/AnalyticsPage';
import SettingsPage from './pages/SettingsPage';
import NotificationsPage from './pages/NotificationsPage';
import Layout from './components/Layout';

const useStyles = makeStyles({
  appContainer: {
    height: '100vh',
    display: 'flex',
    flexDirection: 'column',
  },
});

const App: React.FC = () => {
  const classes = useStyles();
  const isAuthenticated = useSelector((state: RootState) => state.auth.isAuthenticated);

  if (!isAuthenticated) {
    return (
      <div className={classes.appContainer}>
        <Routes>
          <Route path="/login" element={<LoginPage />} />
          <Route path="*" element={<Navigate to="/login" replace />} />
        </Routes>
      </div>
    );
  }

  return (
    <div className={classes.appContainer}>
      <Layout>
        <Routes>
          <Route path="/" element={<Navigate to="/dashboard" replace />} />
          <Route path="/dashboard" element={<DashboardPage />} />
          <Route path="/opportunities" element={<OpportunityListPage />} />
          <Route path="/opportunities/:id" element={<OpportunityDetailPage />} />
          <Route path="/business-plans" element={<BusinessPlanPage />} />
          <Route path="/progress-tracking" element={<ProgressTrackingPage />} />
          <Route path="/risk-management" element={<RiskManagementPage />} />
          <Route path="/analytics" element={<AnalyticsPage />} />
          <Route path="/settings" element={<SettingsPage />} />
          <Route path="/notifications" element={<NotificationsPage />} />
          <Route path="*" element={<Navigate to="/dashboard" replace />} />
        </Routes>
      </Layout>
    </div>
  );
};

export default App;